using System;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using HelloWorld.Controllers;
using Phoenix;
using Phoenix.Commands;
using Phoenix.Events;

namespace HelloWorld.ViewModels.Home
{
    public class IndexViewModel : ViewModelBase, IListener<Test>
    {
        public IndexViewModel()
        {
            ExampleCommand = new DelegateCommand(()=>MessageBox.Show("Hi from command"));
            ReturnSomethingCommand = new DelegateCommand(GetResult);
        }

        protected override void OnActivated()
        {
            //GetResult();
        }

        protected override void OnDeactivated()
        {
            base.OnDeactivated();
        }

        void GetResult()
        {


            Controller<HomeController>().InvokeActionWithResult<string>(c => c.GetMessage())
                .ContinueWith(t => MessageBox.Show(t.Result), TaskScheduler.FromCurrentSynchronizationContext());
        }

        public string Name { get { return "Test"; } }

        public ICommand ExampleCommand { get; private set; }

        public ICommand ReturnSomethingCommand { get; private set; }

        public void Handle(Test message)
        {
            
        }
    }

    public class Test {}
}